<%@ page import="static javax.swing.UIManager.getString" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.Statement" %><%--
  Created by IntelliJ IDEA.
  User: hua'wei
  Date: 2023/5/18
  Time: 17:32
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script>
        function decrease() {
            var quantity = document.getElementById("quantity");
            var value = parseInt(quantity.value);
            if (value > 1) {
                quantity.value = value - 1;
            }
        }

        function increase() {
            var quantity = document.getElementById("quantity");
            var value = parseInt(quantity.value);
            quantity.value = value + 1;
        }

    </script>


</head>
<body>
<div align="center">
    <h1>商品详细</h1>
    <br>
    <br>
    <br>
    <br>
</div>
<%
    String shop = request.getParameter("shop");
    System.out.println(shop);
    String url = "jdbc:mysql://localhost:3306/cart?serverTimezone=Asia/Shanghai";
    String user = "root";
    String password = "111111";
    Connection conn = null;
    ResultSet rs = null;
    Statement stmt = null;
    try {
        Class.forName("com.mysql.jdbc.Driver");
        conn = DriverManager.getConnection(url, user, password);
        stmt = conn.createStatement();
        String sql = "select * from shop where shop='" + shop + "'";
        rs = stmt.executeQuery(sql);
        while (rs.next()) {
%>
<table width="500" border="1" cellpadding="0" align="center">
    <tr>
        <td align="center">商品id：</td>
        <td>&nbsp;<%=rs.getString("id")%></td>
    </tr>
    <tr>
        <td align="center">商品名称：</td>
        <td>&nbsp;<%=rs.getString("shop")%></td>
    </tr>
    <tr>
        <td align="center">商品详细：</td>
        <td>&nbsp;<%=rs.getString("detail")%></td>
    </tr>
    <tr>
        <td align="center">价格：</td>
        <td>&nbsp;<%=rs.getString("price")%></td>
    </tr>
    <tr>
        <td align="center">数量：</td>
        <td>&nbsp;
            <button onclick="decrease()">-</button>
            <input type="text" id="quantity" value="1">
            <button onclick="increase()">+</button>
        </td>
    </tr>
    <tr>
        <div class="operation" align="center">
            <a href="cart.jsp">返回</a>
            <a href="account.jsp?shop=<%=rs.getString("shop")%>">加入购物车</a>
        </div>
    </tr>

    <%
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    %>
</table>


</body>
</html>
